package com.xiaoke.controller;

import com.xiaoke.domain.ResponseResult;
import com.xiaoke.domain.dto.AdminGetArticleListDTO;
import com.xiaoke.domain.dto.CreateArticleDTO;
import com.xiaoke.domain.dto.UpdateArticleDTO;
import com.xiaoke.service.AdminArticleService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


/**
 * 文章表(Article)表后台控制层
 *
 * @author xiaoke
 * @since 2023-03-24 14:15:53
 */
@RestController
@RequestMapping("/admin/article")
public class AdminArticleController {

    @Resource
    AdminArticleService adminArticleService;


    @GetMapping
    public ResponseResult getArticleList(@Validated AdminGetArticleListDTO dto) {
        return adminArticleService.getArticleList(dto);
    }

    @GetMapping("/{id}")
    public ResponseResult getArticle(@PathVariable Long id) {
        return adminArticleService.getArticle(id);
    }

    @PostMapping
    public ResponseResult createArticle(@RequestBody @Validated CreateArticleDTO dto) {
        return adminArticleService.createArticle(dto);
    }

    @DeleteMapping("/{id}")
    public ResponseResult delArticle(@PathVariable Long id) {
        return adminArticleService.delArticle(id);
    }

    @PutMapping("/{id}")
    public ResponseResult updateArticle(@RequestBody @Valid UpdateArticleDTO dto, @PathVariable String id) {
        return adminArticleService.updateArticle(dto,id);
    }


}
